﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PC.AzureMultiApp.Core.Models;
using PC.AzureMultiApp.Storage;
using PC.AzureMultiApp.Core.Helpers;
using PC.AzureMultiApp.Core.Applications;
using PC.AzureMultiApp.WebRoleMultiApp.Helpers;

namespace PC.AzureMultiApp.WebRoleMultiApp.Controllers
{
    [ValidaAdminRole()]  
    public class EditController : Controller
    {
        public ActionResult Edit(string id)
        {
            return View(Applications.GetById(id));
        }


        [HttpPost]
        public ActionResult Edit(string id, ApplicationModel app)
        {
            app.ApplicationUrl = app.IsWebDeploy ?
                    String.Format("http://{0}/{1}", HttpContext.Request.Url.Host, app.ApplicationName) : string.Empty;

            Applications.Edit(id, app);

            return RedirectToAction("Application", "Application");
        }

       
    }
}
